package io.github.thundzeng.miniemail.starter.autoconfigure;

import io.github.thundzeng.miniemail.core.MiniEmailFactory;
import io.github.thundzeng.miniemail.core.MiniEmailFactoryBuilder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 建立 MiniEmailFactory
 *
 * @author thundzeng
 */
@EnableConfigurationProperties(value = {MiniEmailProperties.class})
@Configuration
public class MiniEmailFactoryAutoConfiguration {
    private final MiniEmailFactory factory;

    public MiniEmailFactoryAutoConfiguration(MiniEmailProperties properties) {
        factory = build(properties);
    }

    private MiniEmailFactory build(MiniEmailProperties properties) {
        return new MiniEmailFactoryBuilder().build(properties);
    }

    @Bean(value = "miniEmailFactory")
    public MiniEmailFactory miniEmailFactory() {
        return factory;
    }

}
